// Profiler.h : Declaration of the CProfiler

#pragma once
#include "resource.h"       // main symbols



#include "MyClrProfiler_i.h"



#if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
#error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms."
#endif

using namespace ATL;


// CProfiler

class ATL_NO_VTABLE CProfiler :
	public CComObjectRootEx<CComMultiThreadModel>,
	public CComCoClass<CProfiler, &CLSID_Profiler>,
	public IProfiler,
	public ICorProfilerCallback3
{
public:
	CProfiler()
	{
	}

	DECLARE_REGISTRY_RESOURCEID(IDR_PROFILER)

	DECLARE_NOT_AGGREGATABLE(CProfiler)

	BEGIN_COM_MAP(CProfiler)
		COM_INTERFACE_ENTRY(IProfiler)
		COM_INTERFACE_ENTRY(ICorProfilerCallback)
		COM_INTERFACE_ENTRY(ICorProfilerCallback2)
		COM_INTERFACE_ENTRY(ICorProfilerCallback3)
	END_COM_MAP()

	DECLARE_PROTECT_FINAL_CONSTRUCT()

	HRESULT FinalConstruct()
	{
		return S_OK;
	}

	void FinalRelease()
	{
	}

private:
	
	ICorProfilerInfo3* m_pICorProfiler3;

	void AcquireProfilerInterfaces(IUnknown *pUnknown);
	void EnableProfilerEvents();

public:

	static void  Enter( FunctionID functionID );
	static void  Leave( FunctionID functionID );
	static void  Tailcall( FunctionID functionID );

	//
	// ICorProfilerCallback (inherits IUnknown)
	//

	HRESULT STDMETHODCALLTYPE Initialize( 
		IUnknown *pICorProfilerInfoUnk);

	HRESULT STDMETHODCALLTYPE Shutdown( void)  { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE AppDomainCreationStarted( 
		AppDomainID appDomainId) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE AppDomainCreationFinished( 
		AppDomainID appDomainId,
		HRESULT hrStatus) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE AppDomainShutdownStarted( 
		AppDomainID appDomainId) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE AppDomainShutdownFinished( 
		AppDomainID appDomainId,
		HRESULT hrStatus) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE AssemblyLoadStarted( 
		AssemblyID assemblyId) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE AssemblyLoadFinished( 
		AssemblyID assemblyId,
		HRESULT hrStatus) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE AssemblyUnloadStarted( 
		AssemblyID assemblyId) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE AssemblyUnloadFinished( 
		AssemblyID assemblyId,
		HRESULT hrStatus) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE ModuleLoadStarted( 
		ModuleID moduleId) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE ModuleLoadFinished( 
		ModuleID moduleId,
		HRESULT hrStatus) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE ModuleUnloadStarted( 
		ModuleID moduleId) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE ModuleUnloadFinished( 
		ModuleID moduleId,
		HRESULT hrStatus) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE ModuleAttachedToAssembly( 
		ModuleID moduleId,
		AssemblyID AssemblyId) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE ClassLoadStarted( 
		ClassID classId) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE ClassLoadFinished( 
		ClassID classId,
		HRESULT hrStatus) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE ClassUnloadStarted( 
		ClassID classId) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE ClassUnloadFinished( 
		ClassID classId,
		HRESULT hrStatus) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE FunctionUnloadStarted( 
		FunctionID functionId) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE JITCompilationStarted( 
		FunctionID functionId,
		BOOL fIsSafeToBlock);

	HRESULT STDMETHODCALLTYPE JITCompilationFinished( 
		FunctionID functionId,
		HRESULT hrStatus,
		BOOL fIsSafeToBlock) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE JITCachedFunctionSearchStarted( 
		FunctionID functionId,
		/* [out] */ BOOL *pbUseCachedFunction) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE JITCachedFunctionSearchFinished( 
		FunctionID functionId,
		COR_PRF_JIT_CACHE result) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE JITFunctionPitched( 
		FunctionID functionId) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE JITInlining( 
		FunctionID callerId,
		FunctionID calleeId,
		/* [out] */ BOOL *pfShouldInline) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE ThreadCreated( 
		ThreadID threadId) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE ThreadDestroyed( 
		ThreadID threadId) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE ThreadAssignedToOSThread( 
		ThreadID managedThreadId,
		DWORD osThreadId) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE RemotingClientInvocationStarted( void) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE RemotingClientSendingMessage( 
		GUID *pCookie,
		BOOL fIsAsync) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE RemotingClientReceivingReply( 
		GUID *pCookie,
		BOOL fIsAsync) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE RemotingClientInvocationFinished( void) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE RemotingServerReceivingMessage( 
		GUID *pCookie,
		BOOL fIsAsync) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE RemotingServerInvocationStarted( void) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE RemotingServerInvocationReturned( void) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE RemotingServerSendingReply( 
		GUID *pCookie,
		BOOL fIsAsync) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE UnmanagedToManagedTransition( 
		FunctionID functionId,
		COR_PRF_TRANSITION_REASON reason) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE ManagedToUnmanagedTransition( 
		FunctionID functionId,
		COR_PRF_TRANSITION_REASON reason) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE RuntimeSuspendStarted( 
		COR_PRF_SUSPEND_REASON suspendReason) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE RuntimeSuspendFinished( void) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE RuntimeSuspendAborted( void) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE RuntimeResumeStarted( void) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE RuntimeResumeFinished( void) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE RuntimeThreadSuspended( 
		ThreadID threadId) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE RuntimeThreadResumed( 
		ThreadID threadId) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE MovedReferences( 
		ULONG cMovedObjectIDRanges,
		ObjectID oldObjectIDRangeStart[  ],
		ObjectID newObjectIDRangeStart[  ],
		ULONG cObjectIDRangeLength[  ]) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE ObjectAllocated( 
		ObjectID objectId,
		ClassID classId) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE ObjectsAllocatedByClass( 
		ULONG cClassCount,
		ClassID classIds[  ],
		ULONG cObjects[  ]) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE ObjectReferences( 
		ObjectID objectId,
		ClassID classId,
		ULONG cObjectRefs,
		ObjectID objectRefIds[  ]) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE RootReferences( 
		ULONG cRootRefs,
		ObjectID rootRefIds[  ]) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE ExceptionThrown( 
		ObjectID thrownObjectId) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE ExceptionSearchFunctionEnter( 
		FunctionID functionId) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE ExceptionSearchFunctionLeave( void) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE ExceptionSearchFilterEnter( 
		FunctionID functionId) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE ExceptionSearchFilterLeave( void) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE ExceptionSearchCatcherFound( 
		FunctionID functionId) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE ExceptionOSHandlerEnter( 
		UINT_PTR __unused) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE ExceptionOSHandlerLeave( 
		UINT_PTR __unused) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE ExceptionUnwindFunctionEnter( 
		FunctionID functionId) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE ExceptionUnwindFunctionLeave( void) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE ExceptionUnwindFinallyEnter( 
		FunctionID functionId) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE ExceptionUnwindFinallyLeave( void) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE ExceptionCatcherEnter( 
		FunctionID functionId,
		ObjectID objectId) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE ExceptionCatcherLeave( void) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE COMClassicVTableCreated( 
		ClassID wrappedClassId,
		REFGUID implementedIID,
		void *pVTable,
		ULONG cSlots) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE COMClassicVTableDestroyed( 
		ClassID wrappedClassId,
		REFGUID implementedIID,
		void *pVTable) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE ExceptionCLRCatcherFound( void) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE ExceptionCLRCatcherExecute( void) { return E_FAIL; }

	//
	// ICorProfilerCallback2 (inherits ICorProfilerCallback)
	//

	HRESULT STDMETHODCALLTYPE ThreadNameChanged( 
		ThreadID threadId,
		ULONG cchName,

		_In_reads_opt_(cchName)  WCHAR name[  ]) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE GarbageCollectionStarted( 
		int cGenerations,
		BOOL generationCollected[  ],
		COR_PRF_GC_REASON reason) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE SurvivingReferences( 
		ULONG cSurvivingObjectIDRanges,
		ObjectID objectIDRangeStart[  ],
		ULONG cObjectIDRangeLength[  ]) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE GarbageCollectionFinished( void) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE FinalizeableObjectQueued( 
		DWORD finalizerFlags,
		ObjectID objectID) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE RootReferences2( 
		ULONG cRootRefs,
		ObjectID rootRefIds[  ],
		COR_PRF_GC_ROOT_KIND rootKinds[  ],
		COR_PRF_GC_ROOT_FLAGS rootFlags[  ],
		UINT_PTR rootIds[  ]) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE HandleCreated( 
		GCHandleID handleId,
		ObjectID initialObjectId) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE HandleDestroyed( 
		GCHandleID handleId) { return E_FAIL; }

	//
	// ICorProfilerCallback3 (inherits ICorProfilerCallback2)
	//

	HRESULT STDMETHODCALLTYPE InitializeForAttach( 
		IUnknown *pCorProfilerInfoUnk,
		void *pvClientData,
		UINT cbClientData) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE ProfilerAttachComplete( void) { return E_FAIL; }

	HRESULT STDMETHODCALLTYPE ProfilerDetachSucceeded( void) { return E_FAIL; }


};

OBJECT_ENTRY_AUTO(__uuidof(Profiler), CProfiler)
